package com.seele.tigerwallet.ui.activtiy;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.seele.tigerwallet.R;
import com.seele.tigerwallet.ui.base.BaseActivity;
import com.seele.tigerwallet.ui.manager.LoadingManager;
import com.seele.tigerwallet.utils.EthWalletUtil;

import java.util.ArrayList;
import java.util.List;

public class SelectActivity extends BaseActivity {

    private LinearLayout mLayoutTips;//警告界面
    private LinearLayout mLayoutCreateWallet;//选择界面
    private List<String> mnemonicCode;//钱包助记词


    @Override
    protected int getLayoutId() {
        return R.layout.activity_select;
    }

    @Override
    protected void init() {
        initWidow();
        initView();
    }

    private void initView() {
        mLayoutTips = (LinearLayout) findViewById(R.id.layout_tips);
        mLayoutCreateWallet = (LinearLayout) findViewById(R.id.layout_wallet_create);
    }


    /**
     * 切换布局
     */
    private void onBtnOk() {
        mLayoutTips.setVisibility(View.GONE);
        mLayoutCreateWallet.setVisibility(View.VISIBLE);
    }


    public void onBtnClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                onBtnOk();
                break;
            case R.id.btn_create_wallet://创建钱包
                try {
                    getLoadingManager().showLoadingDialog();
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            final List<String>  mnemonicCode = EthWalletUtil.getMnemonicCode();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    if (null!=mnemonicCode&&mnemonicCode.size()>0){
                                        Bundle bundle=new Bundle();
                                        bundle.putStringArrayList(CreateEthWalletActivity.TAG, (ArrayList<String>) mnemonicCode);
                                        startActivity(CreateEthWalletActivity.class,bundle);
                                    }
                                }
                            });
                        }
                    }).start();

                } catch (Exception e) {
                    e.printStackTrace();
                }
                dismissLoadingDialog();
                break;
            case R.id.btn_import_wallet://导入钱包
                onImportWallet();
                break;

        }

    }

    private void onImportWallet() {
        startActivity(ImportWalletActivity.class);

    }

    private void onCreateEthWallet() {
        startActivity(CreateEthWalletActivity.class);
    }
}
